import requests
from pip._internal.network.session import HTTPAdapter
from urllib3 import Retry


def get_wikipedia_data(query):
    url = "https://en.wikipedia.org/w/api.php"
    params = {
        "action": "query",
        "format": "json",
        "titles": query,
        "prop": "extracts",
        "exintro": True,
        "explaintext": True
    }

    session = requests.Session()
    retry = Retry(total=3, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)

    try:
        response = session.get(url, params=params)
        response.raise_for_status()
        data = response.json()
        print(f"Successfully retrieved Wikipedia data.{data}")
        print("-=================================")
        pages = data['query']['pages']
        page_id = list(pages.keys())[0]
        content = pages[page_id]['extract']
        return content
    except requests.exceptions.RequestException as e:
        print(f"An error occurred: {e}")
        return None

if __name__ == "__main__":
    content = get_wikipedia_data("Elizabeth I")
    if content:
        print(content)